package com.yanqu.road.server.cmd.passRoad;

import com.yanqu.road.pb.pass.RoadTransportProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.passRoad.PassTransportModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;


@Cmd(code = Protocol.S_PASS_ROAD_TRANSPORT_LOAD, desc = "新关卡更换坐骑处理")
public class PassRoadLoadTransportCmd extends AbstractCommand {

	private int tpId;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		RoadTransportProto.PassTransportChangeReqMsg reqMsg = RoadTransportProto.PassTransportChangeReqMsg.parseFrom(packet.getBytes());
		tpId = reqMsg.getTpId();
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		ret = player.getModule(PassTransportModule.class).loadTransport(tpId);
	}

	@Override
	public void sendData(GamePlayer player) {
		RoadTransportProto.PassTransportChangeRespMsg.Builder respMsg = RoadTransportProto.PassTransportChangeRespMsg.newBuilder();
		respMsg.setRet(ret);
		player.sendPacket(Protocol.U_PASS_ROAD_TRANSPORT_LOAD, respMsg);
	}
}
